package com.pzhu.user.domain.vo.converter;

import com.mybatisflex.core.paginate.Page;
import com.pzhu.user.domain.entity.Role;
import com.pzhu.user.domain.vo.RoleSearchVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import com.pzhu.base.common.utils.json.JSONUtils;
import com.pzhu.base.common.utils.result.PageData;

import java.util.List;

@Mapper(
        componentModel = MappingConstants.ComponentModel.SPRING,
        imports = {JSONUtils.class})
public interface RoleVOConverter {

    default PageData<RoleSearchVO> convert(Page<Role> rolePage) {
        List<Role> pageRecords = rolePage.getRecords();
        List<RoleSearchVO> searchRespList = convert(pageRecords);
        return new PageData<>(searchRespList, rolePage.getTotalRow());
    }

    @Mapping(target = "roleName", source = "roleDesc")
    @Mapping(target = "roleCode", source = "code")
    RoleSearchVO convert(Role role);

    List<RoleSearchVO> convert(List<Role> roles);
}
